using System;
using System.Windows.Forms;

namespace AreaBuilder.Input {
    public partial class InputBox : Form {
        public bool OK;
        public bool Cancel;
        public String selected;

        public InputBox(String question, String caption, String[] options) {
            InitializeComponent();

            lblQuestion.Text = question;
// ReSharper disable DoNotCallOverridableMethodsInConstructor
            Text = caption;
// ReSharper restore DoNotCallOverridableMethodsInConstructor

            for (int i = 0; i < options.Length; i++)
                cmbOptions.Items.Add(options[i]);

            cmbOptions.SelectedIndex = 0;

            cmbOptions.Visible = true;

            cmbOptions.Focus();
        }

        public InputBox(String question, String caption, String defaultOpt) {
            InitializeComponent();

            lblQuestion.Text = question;
// ReSharper disable DoNotCallOverridableMethodsInConstructor
            Text = caption;
// ReSharper restore DoNotCallOverridableMethodsInConstructor

            txtDefault.Text = defaultOpt;
            txtDefault.Visible = true;

            txtDefault.Focus();
        }

        private void InputBox_Load(object sender, EventArgs e) { 
        }

        private void btnCancel_Click(object sender, EventArgs e) {
            Cancel = true;

            Dispose();
        }

        private void btnOK_Click(object sender, EventArgs e) {
            OK = true;

            selected = cmbOptions.Visible ? cmbOptions.SelectedItem.ToString() : txtDefault.Text;

            Close();
        }

        private void txtDefault_KeyPress(object sender, KeyPressEventArgs e) {
            if (e.KeyChar == 13) btnOK_Click(null, null);
        }

        private void cmbOptions_KeyPress(object sender, KeyPressEventArgs e) {
            if (e.KeyChar == 13) btnOK_Click(null, null);
        }
    }
}